<?php
require("connect.php");

class PushData 
{
	public $title;
	public $statement;
	public $uNews;
	public $content;
	public $image;
	public $description;
	public $date;
	
	function __constructor()
	{		
	}
	
	function getData()
	{
            $query = "SELECT uNews,title,statement,content
                            FROM news";   
            $Result = mysql_query($query);
            $numrow = mysql_num_rows($Result);
            if ($numrow != 0) {            
                while ($row = mysql_fetch_assoc($Result)) {                
                    $uNews = $row['uNews'];                 
                    $title = $row['title'];
                    $statement = $row['statement'];
                    if($statement!=0){
                        echo '<tr>';
                        echo'<td align="center">'.$uNews.'</td>';
                        echo'<td align="center"><a href="../index_test.php?uNews='.$uNews.'">'.$title.'</a></td>';//bug occur here please check and fix it
                        echo'<td align="center">'.$statement.'</td>';
                        echo'<td align="center"><a href="article_edit.php?uNews='.$uNews.'">'.'<img src="../images/icon-48-article-edit.png" height="25" width="25" border="0">'.'</a></td>';
                        echo'<td align="center"><a href="article_delete.php?uNews='.$uNews.'">'.'<img src="../images/delete.png" height="25" width="25" border="0">'.'</a></td>';
                        echo'</tr>';
                    }
                }
            }
	}

        function loadArticle($uNew){
            $query = 'select * from news where uNews='.$uNew;
            $result= mysql_query($query);
            $row = mysql_num_rows($result);
            if($row <= 0) {
                echo 'No data';
                return null;
            } else {
                $article = new PushData();                    
                while($r1=  mysql_fetch_assoc($result)) {                  
                    $article->uNews = $r1['uNews'];
                    $article->title = $r1['title'];
                    $article->description = $r1['description'];
                    $article->image = $r1['image'];
                    $article->content = $r1['content'];                   
                    $article->author = $r1['author'];
                    $article->date =$r1['date'];
                    $article->statement = $r1['statement'];
                }
                return $article;
            }
        }
}
?>